#extension GL_OES_EGL_image_external : require
varying vec2 vTextureCoord;
uniform samplerExternalOES           sTexture;
uniform float mosaicSize;
uniform vec3 iResolution;
uniform float iTime;
// Created by David Bargo - davidbargo/2015
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

#define ANIMATE

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 xy = vec2(fragCoord.x * iResolution.x, fragCoord.y * iResolution.y);// 取值范围换算到图像尺寸大小
    // 计算某一个小mosaic的中心坐标
    vec2 xyMosaic = vec2(floor(xy.x / mosaicSize) * mosaicSize, floor(xy.y / mosaicSize) * mosaicSize )
          + .5*mosaicSize;
    // 计算距离中心的长度
    vec2 delXY = xyMosaic - xy;
    float delL = length(delXY);
    // 换算回纹理坐标系
    vec2 uvMosaic = vec2(xyMosaic.x / iResolution.x, xyMosaic.y / iResolution.y);

    if(delL<0.5*mosaicSize)
    {
       fragColor = texture2D(sTexture, uvMosaic);
    }
    else
    {
       //finalColor = texture2D(Texture0, vUV);
       fragColor = vec4(0., 0., 0., 1.);
    }

}

void main(void)
{
    mainImage(gl_FragColor, vTextureCoord);
}